import request from '../../utils/request'

/**
 * 轮播图相关API接口
 */

export interface Banner {
  id: string
  title: string
  imageUrl: string
  link?: string
  position: string
  isActive: boolean
  order: number
  createTime: string
}

export interface BannerListParams {
  position?: string
  status?: 'active' | 'inactive' | 'all'
  page?: number
  pageSize?: number
}

export interface BannerFormData {
  id?: string
  title: string
  imageUrl: string
  link?: string
  position: string
  isActive: boolean
  order: number
}

/**
 * 获取轮播图列表
 */
export function getBanners(params: BannerListParams = {}) {
  return request<Banner[]>({
    url: '/banners',
    method: 'GET',
    params
  })
}

/**
 * 获取轮播图详情
 */
export function getBannerDetail(id: string) {
  return request<Banner>({
    url: `/banners/${id}`,
    method: 'GET'
  })
}

/**
 * 创建轮播图
 */
export function createBanner(data: BannerFormData) {
  return request<Banner>({
    url: '/banners',
    method: 'POST',
    data
  })
}

/**
 * 更新轮播图
 */
export function updateBanner(id: string, data: Partial<BannerFormData>) {
  return request<Banner>({
    url: `/banners/${id}`,
    method: 'PUT',
    data
  })
}

/**
 * 删除轮播图
 */
export function deleteBanner(id: string) {
  return request<null>({
    url: `/banners/${id}`,
    method: 'DELETE'
  })
}

/**
 * 更新轮播图状态
 */
export function updateBannerStatus(id: string, isActive: boolean) {
  return request<Banner>({
    url: `/banners/${id}/status`,
    method: 'PATCH',
    data: { isActive }
  })
}

/**
 * 更新轮播图排序
 */
export function updateBannerOrder(data: { id: string, order: number }[]) {
  return request<null>({
    url: '/banners/order',
    method: 'PATCH',
    data
  })
}

/**
 * 上传轮播图图片
 */
export function uploadBannerImage(data: FormData) {
  return request<{ url: string }>({
    url: '/upload/banner',
    method: 'POST',
    headers: {
      'Content-Type': 'multipart/form-data'
    },
    data
  })
} 